/**
 * Created by Administrator on 2019/11/26.
 */
import { deleteUserConfigCustom, setUserConfigCustom } from '@/api/auth/authUserConfigCustomApi'

import { localStorageGet, localStorageSet } from './common'

function saveToNet(key, value) {
  localStorageSet(key, value)
  if (getToken() === null) {
    return
  }
  if (value === null) {
    deleteUserConfigCustom({
      keyName: key
    })
  } else {
    setUserConfigCustom({
      keyName: key,
      value: value
    })
  }
}

function getFromNet(key) {
  return localStorageGet(key)
}

const domain = window.location.host + '_'

export function getHostName() {
  return window.location.hostname
}

const safeModelKey = domain + 'safeModel'

export function setSafeModel(safeModel) {
  return localStorageSet(safeModelKey, safeModel ? '1' : '0')
}

export function getSafeModel() {
  return localStorageGet(safeModelKey) === '1'
}

const mapTypeKey = domain + 'mapType'

export function setMapType(mapType) {
  return saveToNet(mapTypeKey, mapType)
}

export function getMapType() {
  return getFromNet(mapTypeKey) || 'baidu'
}

const inChinaKey = domain + 'inChina'

export function setInChina(inChina) {
  return saveToNet(inChinaKey, inChina)
}

export function getInChina() {
  return getFromNet(inChinaKey) || 'true'
}

const mapZoomKey = domain + 'mapZoom'

export function setMapZoom(mapZoom) {
  return saveToNet(mapZoomKey, mapZoom)
}

export function getMapZoom() {
  return getFromNet(mapZoomKey) || 5
}

const deptIdKey = domain + 'deptId'

export function getDeptId() {
  return localStorageGet(deptIdKey) || '-1'
}

export function setDeptId(deptId) {
  return localStorageSet(deptIdKey, deptId)
}

const safeCodeKey = domain + 'safeCode'

export function getSafeCode() {
  return localStorageGet(safeCodeKey) || ''
}

export function setSafeCode(safeCode) {
  return localStorageSet(safeCodeKey, safeCode)
}

const mapModelKey = domain + 'mapModel'

export function getMapModel() {
  return getFromNet(mapModelKey) || 'point'
}

export function setMapModel(mapModel) {
  return saveToNet(mapModelKey, mapModel)
}

const mapGatherKey = domain + ' mapGather'

export function getMapGather() {
  return getFromNet(mapGatherKey) || '1'
}

export function setMapGather(mapGather) {
  return saveToNet(mapGatherKey, mapGather)
}

const pageSizeKey = domain + 'pageSize'

export function getPageSize() {
  const pageSize = getFromNet(pageSizeKey)
  return pageSize ? parseInt(pageSize) : 20
}

export function setPageSize(pageSize) {
  return saveToNet(pageSizeKey, pageSize)
}

const gridNumKey = domain + 'gridNum'

export function getGridNum() {
  return getFromNet(gridNumKey) || '2'
}

export function setGridNum(gridNum) {
  return saveToNet(gridNumKey, gridNum)
}

const showParamListKey = domain + 'showParamList'

export function getShowParamList() {
  return getFromNet(showParamListKey) || '1'
}

export function setShowParamList(showParamList) {
  return saveToNet(showParamListKey, showParamList)
}

const showSensorAutoKey = domain + 'showSensorAuto'

export function getShowSensorAuto() {
  return getFromNet(showSensorAutoKey) || '1'
}

export function setShowSensorAuto(showSensorAuto) {
  return saveToNet(showSensorAutoKey, showSensorAuto)
}

const showExplainListKey = domain + 'showExplainList'

export function getShowExplainList() {
  return getFromNet(showExplainListKey) || '1'
}

export function setShowExplainList(showExplainList) {
  return saveToNet(showExplainListKey, showExplainList)
}

const showSearchInfoKey = domain + 'showSearchInfo'

export function getShowSearchInfo() {
  return getFromNet(showSearchInfoKey) || '1'
}

export function setShowSearchInfo(showSearchInfo) {
  return saveToNet(showSearchInfoKey, showSearchInfo)
}

const showCameraListKey = domain + 'showCameraList'

export function getShowCameraList() {
  return getFromNet(showCameraListKey) || '1'
}

export function setShowCameraList(showCameraList) {
  return saveToNet(showCameraListKey, showCameraList)
}

const showSettingListKey = domain + 'showSettingList'

export function getShowSettingList() {
  return getFromNet(showSettingListKey) || '1'
}

export function setShowSettingList(showSettingList) {
  return saveToNet(showSettingListKey, showSettingList)
}

const showViewKey = domain + 'showView'

export function getShowView() {
  return getFromNet(showViewKey) || '1'
}

export function setShowView(showView) {
  return saveToNet(showViewKey, showView)
}

const showChildDeviceKey = domain + 'showChildDevice'

export function getShowChildDevice() {
  return getFromNet(showChildDeviceKey) || '1'
}

export function setShowChildDevice(showChildDevice) {
  return saveToNet(showChildDeviceKey, showChildDevice)
}

const sizeKey = domain + 'size'

export function getSize() {
  return getFromNet(sizeKey)
}

export function setSize(size) {
  return saveToNet(sizeKey, size)
}

const latKey = domain + 'lat'

export function getLat() {
  return localStorageGet(latKey)
}

export function setLat(lat) {
  return localStorageSet(latKey, lat)
}

const lngKey = domain + 'lng'

export function getLng() {
  return localStorageGet(lngKey)
}

export function setLng(lng) {
  return localStorageSet(lngKey, lng)
}

const filterRepeatKey = domain + 'filterRepeat'

export function getFilterRepeat() {
  return getFromNet(filterRepeatKey) || '1'
}

export function setFilterRepeat(filterRepeat) {
  return saveToNet(filterRepeatKey, filterRepeat)
}

const showHiddenKey = domain + 'showHidden'

export function getShowHidden() {
  return getFromNet(showHiddenKey) || '0'
}

export function setShowHidden(showHidden) {
  return saveToNet(showHiddenKey, showHidden)
}

const addFrameKey = domain + 'addFrame'

export function getAddFrame() {
  return getFromNet(addFrameKey) || '0'
}

export function setAddFrame(addFrame) {
  return saveToNet(addFrameKey, addFrame)
}

const sidebarStatusKey = domain + 'sidebarStatus'

export function getSidebarStatus() {
  return localStorageGet(sidebarStatusKey)
}

export function setSidebarStatus(sidebarStatus) {
  return localStorageSet(sidebarStatusKey, sidebarStatus)
}

const qrCodeBaseUrlKey = domain + 'qrCodeBaseUrl'

export function getQrCodeBaseUrl() {
  return localStorageGet(qrCodeBaseUrlKey)
}

export function setQrCodeBaseUrl(qrCodeBaseUrl) {
  return localStorageSet(qrCodeBaseUrlKey, qrCodeBaseUrl)
}

const forReferenceInfoKey = domain + 'forReferenceInfo'

export function getForReferenceInfo() {
  return localStorageGet(forReferenceInfoKey)
}

export function setForReferenceInfo(forReferenceInfo) {
  return localStorageSet(forReferenceInfoKey, forReferenceInfo)
}

const TokenKey = domain + 'accessToken'

export function getToken() {
  if (getSafeModel()) {
    return sessionStorage.getItem(TokenKey)
  }
  return localStorageGet(TokenKey)
}

export function setToken(token) {
  if (getSafeModel()) {
    return sessionStorage.setItem(TokenKey, token)
  }
  return localStorageSet(TokenKey, token)
}

const isDemoAccountKey = domain + 'isDemoAccount'

export function setIsDemoAccount(isDemoAccount) {
  localStorageSet(isDemoAccountKey, isDemoAccount)
}

// const checkrememberKey = domain + 'checkremember'
//
// export function setCheckremember(checkremember) {
//   localStorageSet(checkrememberKey, checkremember)
// }

const fixedHeaderKey = domain + 'fixedHeader'

export function getFixedHeader() {
  return localStorageGet(fixedHeaderKey)
}

export function setFixedHeader(fixedHeader) {
  localStorageSet(fixedHeaderKey, fixedHeader)
}

const tagsViewKey = domain + 'tagsView'

export function getTagsView() {
  return localStorageGet(tagsViewKey)
}

export function setTagsView(tagsView) {
  localStorageSet(tagsViewKey, tagsView)
}

const sidebarLogoKey = domain + 'sidebarLogo'

export function setSidebarLogo(sidebarLogo) {
  localStorageSet(sidebarLogoKey, sidebarLogo)
}

export function getSidebarLogo() {
  return localStorageGet(sidebarLogoKey)
}

const themeColorKey = domain + 'themeColor'

export function setThemeColor(themeColor) {
  localStorageSet(themeColorKey, themeColor)
}

export function getThemeColor() {
  return localStorageGet(themeColorKey)
}

const userNameKey = domain + 'userName'

export function getUserName() {
  return localStorageGet(userNameKey)
}

export function setUserName(userName) {
  localStorageSet(userNameKey, userName)
}

const userIdKey = domain + 'userId'

export function getUserId() {
  return localStorageGet(userIdKey) || null
}

export function setUserId(userId) {
  localStorageSet(userIdKey, userId)
}

const qrCodeTempKey = domain + 'qrCodeTemp'

export function getQrCodeTemp() {
  return localStorageGet(qrCodeTempKey)
}

export function setQrCodeTemp(qrCodeTemp) {
  localStorageSet(qrCodeTempKey, qrCodeTemp)
}

const devModelKey = domain + 'devModel'

export function getDevModel() {
  return localStorageGet(devModelKey)
}

export function setDevModel(devModel) {
  localStorageSet(devModelKey, devModel)
}

const languageKey = domain + 'language'

export function getLanguage() {
  return getFromNet(languageKey) || null
}

export function setLanguage(language) {
  return saveToNet(languageKey, language)
}

const lastVersionKey = domain + 'lastVersion'

export function getLastVersion() {
  return getFromNet(lastVersionKey) || ''
}

export function setLastVersion(lastVersion) {
  saveToNet(lastVersionKey, lastVersion)
}

export function getAppVersion() {
  return process.env.VUE_APP_VERSION
}

const netModelKey = domain + 'netModel'

export function getNetModel() {
  return localStorageGet(netModelKey) || ''
}

export function setNetModel(netModel) {
  localStorageSet(netModelKey, netModel)
}

const companyNameKey = domain + 'companyName'

export function getCompanyName() {
  return localStorageGet(companyNameKey) || null
}

export function setCompanyName(companyName) {
  localStorageSet(companyNameKey, companyName)
}

const shortCompanyNameKey = domain + 'shortCompanyName'

export function getShortCompanyName() {
  return localStorageGet(shortCompanyNameKey) || null
}

export function setShortCompanyName(shortCompanyName) {
  localStorageSet(shortCompanyNameKey, shortCompanyName)
}

const officialUrlKey = domain + 'officialUrl'

export function getOfficialUrl() {
  return localStorageGet(officialUrlKey) || null
}

export function setOfficialUrl(officialUrl) {
  localStorageSet(officialUrlKey, officialUrl)
}

const companyIdKey = domain + 'companyId'

export function getCompanyId() {
  return localStorageGet(companyIdKey) || null
}

export function setCompanyId(companyId) {
  localStorageSet(companyIdKey, companyId)
}

const enablePhoneRegisterKey = domain + 'enablePhoneRegister'

export function getEnablePhoneRegister() {
  return localStorageGet(enablePhoneRegisterKey) || null
}

export function setEnablePhoneRegister(enablePhoneRegister) {
  localStorageSet(enablePhoneRegisterKey, enablePhoneRegister)
}

const enableRegisterKey = domain + 'enableRegister'

export function getEnableRegister() {
  return localStorageGet(enableRegisterKey) || null
}

export function setEnableRegister(enableRegister) {
  localStorageSet(enableRegisterKey, enableRegister)
}

const enableDemoAccountKey = domain + 'enableDemoAccount'

export function getEnableDemoAccount() {
  return localStorageGet(enableDemoAccountKey) || null
}

export function setEnableDemoAccount(enableDemoAccount) {
  localStorageSet(enableDemoAccountKey, enableDemoAccount)
}

const enableServerLinkageKey = domain + 'enableServerLinkage'

export function getEnableServerLinkage() {
  return localStorageGet(enableServerLinkageKey) || null
}

export function setEnableServerLinkage(enableServerLinkage) {
  localStorageSet(enableServerLinkageKey, enableServerLinkage)
}

const companyIconUrlKey = domain + 'companyIconUrl'

export function getCompanyIconUrl() {
  return localStorageGet(companyIconUrlKey) || null
}

export function setCompanyIconUrl(companyIconUrl) {
  localStorageSet(companyIconUrlKey, companyIconUrl)
}

const userIconUrlKey = domain + 'userIconUrl'

export function getUserIconUrl() {
  return localStorageGet(userIconUrlKey) || null
}

export function setUserIconUrl(userIconUrl) {
  localStorageSet(userIconUrlKey, userIconUrl)
}

const loginFromKey = domain + 'loginFrom'

export function getLoginFrom() {
  return localStorageGet(loginFromKey) || null
}

export function setLoginFrom(loginFrom) {
  localStorageSet(loginFromKey, loginFrom)
}

const homePageUrlKey = domain + 'homePageUrl'

export function getHomePageUrl() {
  return localStorageGet(homePageUrlKey) || ''
}

export function setHomePageUrl(homePageUrl) {
  localStorageSet(homePageUrlKey, homePageUrl)
}

const enableEvalKey = domain + 'enableEval'

export function getEnableEval() {
  return getFromNet(enableEvalKey) || '1'
}

export function setEnableEval(enableEval) {
  return saveToNet(enableEvalKey, enableEval)
}

const webSocketUrlKey = domain + 'webSocketUrl'

export function getWebSocketUrl() {
  return getFromNet(webSocketUrlKey)
}

export function setWebSocketUrl(webSocketUrl) {
  return saveToNet(webSocketUrlKey, webSocketUrl)
}

const sensorModelKey = domain + 'sensorModel'

export function getSensorModel() {
  return getFromNet(sensorModelKey) || 'list'
}

export function setSensorModel(sensorModel) {
  return saveToNet(sensorModelKey, sensorModel)
}

const searchDeviceNameKey = domain + 'searchDeviceName'

export function getSearchDeviceName() {
  return getFromNet(searchDeviceNameKey)
}

export function setSearchDeviceName(searchDeviceName) {
  return saveToNet(searchDeviceNameKey, searchDeviceName)
}

const searchDeviceStatusKey = domain + 'searchDeviceStatus'

export function getSearchDeviceStatus() {
  return getFromNet(searchDeviceStatusKey)
}

export function setSearchDeviceStatus(searchDeviceStatus) {
  return saveToNet(searchDeviceStatusKey, searchDeviceStatus)
}

